#! /bin/sh
# PCP QA Test No. 157
# exercise the -u (unbuffered) option for pmlogger (now default)
#
# Copyright (c) 2002 Silicon Graphics, Inc.  All Rights Reserved.
#

seq=`basename $0`
echo "QA output created by $seq"

# get standard environment, filters and checks
. ./common.product
. ./common.filter
. ./common.check

status=0	# success is the default!
trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15


# real QA test starts here

echo "log mandatory on default { sample.bucket }" \
| pmlogger -u -r -l $tmp.log -t 2sec -s 5 $tmp &
_wait_for_pmlogger $! $tmp.log || _exit 1
pmsleep 0.1

prev=0
# expect pmlogger above to run for (5-1)*2sec
for i in 1 2 3 4 5 6 7 8 9 10
do
    if [ -s $tmp.0 ]
    then
	now=`wc -c <$tmp.0 | sed -e 's/ //g'`
	date >> $seq_full
	ls -l $tmp.0 >>$seq_full
	echo "then=$prev now=$now" >>$seq_full
	if [ "$now" -ne "$prev" ]
	then
	    # expect this to happen 5 times.
	    # Note that if _wait_for_pmlogger is slow(er), its possible
	    # that we will see the first samples and log header at once
	    # (and then change will be observed only 4 times).
	    #
	    echo "size changed @"`date` >> $seq_full
	    echo "size changed" >>$tmp.out
	    prev=$now
	fi
    fi
    sleep 1
done

# see note above re. 4 or 5 size changes expected
#
if [ -f $tmp.out ]
then
    head -4 $tmp.out
else
    echo "Badness: no $tmp.out output file created ... pmlogger died?"
    status=1
fi

cat $tmp.log >>$seq_full
pmdumplog -a $tmp >> $seq_full

exit
